<template>
  <el-dialog :title="'选择人员分组'" :close-on-click-modal="false" :visible.sync="visible" width="800px"
             @close="clearDataList()" append-to-body top="8vh">
              <!-- @selection-change="handlefzDataChange" -->
    <el-table :data="fzData" border height="50vh">
      <!-- <el-table-column :selectable="checkSelect" type="selection" width="55" header-align="center"
                       align="center"></el-table-column> -->
      <el-table-column v-if="activeName=='first'" prop="ryfzMc" header-align="center" align="left" label="名称" min-width="150"></el-table-column>
      <el-table-column v-if="activeName=='second'" prop="jgFzName" header-align="center" align="left" label="名称" min-width="150"></el-table-column>
      <el-table-column prop="fzXs" header-align="center" align="center" label="组系数" min-width="100"></el-table-column>
      <el-table-column prop="sl" header-align="center" align="center" label="分组人员数" min-width="100"></el-table-column>
      <el-table-column prop="ryfzSm" header-align="center" align="left" label="说明" min-width="200"></el-table-column>
    </el-table>
    <span slot="footer" style="float: left" class="dialog-footer">
      <el-select v-model="ystype">
        <el-option label="不预设金额" value=""></el-option>
        <el-option label="按分组平均预设金额" value="1"></el-option>
        <el-option label="按分组系数预设金额" value="2"></el-option>
        <el-option label="按分组人员数预设金额" value="3"></el-option>
        <el-option label="按人员均数预设金额" value="4"></el-option>
      </el-select>
      <el-input-number v-if="ystype!=''" v-model="ysNumber" :precision="2" :step="10000" :min="0"
                       style="width: 200px;"></el-input-number>
    </span>
    <span slot="footer" class="dialog-footer">
      <el-button type="primary" @click="btnSave">确定</el-button>
      <el-button type="primary" plain @click="clearDataList">取消</el-button>
    </span>

  </el-dialog>
</template>

<script>
import {getRyfzbList} from '@/api/jiangjin/jiangjinryfzb'


export default {
  data() {
    return {
      visible: false,
      deptId: '',
      fzData: [],

      multiplefzData: [],
      SelectRyStr: "",
      ystype: "",
      ysNumber: 0,
      activeName:""
    }
  },
  methods: {
    init(data,activeName) {
      this.visible = true;
      this.ystype = "";
      this.fzData=data
      this.ysNumber = 0;
      this.activeName=activeName
    //   this.SelectRyStr = "";
    //   this.SelectRyStr = selectRy;
      //this.getInitData();
    },
    getInitData() {
      getRyfzbList(this.deptId).then(res => {
        this.fzData = res.data.data;
      });
    },
    nShowIndex(row, column, cellValue, index) {
      return index + 1;
    },
    handlefzDataChange(val) {
      this.multiplefzData = val;
    },
    checkSelect(row, index) {
      let isCheck = false;
      if (this.SelectRyStr.indexOf(row.id) === -1) {
        isCheck = true;
      }
      if (row.sl) {
        if (row.sl > 0) {
          isCheck = true;
        } else {
          isCheck = false;
        }
      } else {
        isCheck = false;
      }
      return isCheck;
    },
    clearDataList() {
      this.fzData = [];
      this.multiplefzData = [];
      this.visible = false;
    },
    btnSave() {
      if (this.fzData.length === 0) {
        this.$notify.closeAll();
        this.$notify.error('请选择人员分组');
        return;
      }
      var data = this.fzData;
      for (var i in data) {
        data[i].ysNumber = 0;
      }
      if (this.ystype == "1") {
        for (var i in data) {
          data[i].ysNumber = parseFloat((this.ysNumber / data.length).toFixed(2));
        }
      }
      if (this.ystype == "2") {
        var zs = 0;
        for (var i in data) {
          zs += data[i].fzXs*1;
        }
        for (var i in data) {
          data[i].ysNumber = parseFloat((this.ysNumber * data[i].fzXs / zs).toFixed(2));
        }
      }
      if (this.ystype == "3") {
        var zs = 0;
        for (var i in data) {
          zs += data[i].sl*1;
        }
        for (var i in data) {
          data[i].ysNumber = parseFloat((this.ysNumber * data[i].sl / zs).toFixed(2));
        }
      }
      if (this.ystype == "4") {
        for (var i in data) {
          data[i].ysNumber = parseFloat((this.ysNumber * data[i].sl).toFixed(2));
        }
      }
     //console.log("传过去:"+JSON.stringify(data))
      this.$emit("getChildValue", data);
      this.clearDataList();
    }
  }
}
</script>

<style scoped>
</style>
